﻿@{
    ViewBag.Title = "ProductAdd";
    Layout = "~/Views/Shared/_Base.cshtml";
}
@section head{
<script src="@Url.Content("~/Content/roohui/jquery-validation/jquery.validate.min.js")"></script>
<script src="@Url.Content("~/Content/roohui/jquery-validation/jquery.metadata.js")"></script>
<script src="@Url.Content("~/Content/roohui/jquery-validation/messages_cn.js")"></script>
<script type="text/javascript" charset="utf-8" src="../../Content/ueditor/editor_config.js"></script>
<script type="text/javascript" charset="utf-8" src="../../Content/ueditor/editor_all_min.js"></script>
}

<script type="text/javascript">
    var sumeditor = null;
    var rsumeditor = null;
    $(function () {
        $("#btnSave").click(function () {
            var summaryval = sumeditor.getContent().replace(/<\/?.*?>/ig, '');
            var rsumvalue = rsumeditor.getContent().replace(/<\/?.*?>/ig, '');
            try {
                $.ajax({
                    url: "/Product/ProductAdd",
                    data: "productName=" + $("#txtProductName").val() + "&summary=" + summaryval + "&rateSummary=" + rsumvalue,
                    type: "post",
                    success: function (result) {
                        if (result == "OK") {
                            alert("保存成功");
                            location.href = decodeURIComponent("/Product/Index");
                        }
                        else {
                            alert("保存失败。");
                        }
                    }
                });
            }
            catch (err) {
                alert(err.Description);
            }
        });

        $("#btnCancel").click(function () {
            location.href = decodeURIComponent("/Product/Index");
        });
    });

</script>

<div style="overflow-x:hidder;overflow-y:auto;height:100%">
<form action="/" method="post" id="frmProduct" name="frmProduct" style="background-color: white">
<div id="form1" class="liger-form" style="padding-top: 10px;">
    <table cellpadding="0" cellspacing="0" class="l-table-edit">
        <tr>
            <td align="right" class="l-table-edit-td">
                <span class="l-star">*</span>&nbsp;产品名称:
            </td>
            <td align="left" class="l-table-edit-td">
                <input name="txtProductName" type="text" id="txtProductName" ltype="text" validate="{required:true,notnull:true,maxlength:20}"  nullText="不能为空且不超过20个字符"/>
            </td>
            <td align="left">
            </td>
        </tr>
        <tr>
            <td align="right" class="l-table-edit-td">
                <span class="l-star">*</span>&nbsp;产品描述:
            </td>
            <td align="left" class="l-table-edit-td">
                <script name="txtSummary" id="txtSummary" type="text/plain"></script>
                <script type="text/javascript">
                    window.UEDITOR_CONFIG.initialFrameWidth = 500;
                    window.UEDITOR_CONFIG.initialFrameHeight = 150;
                    sumeditor = UE.getEditor('txtSummary');
                </script>
            </td>
            <td align="left">
            </td>
        </tr>
        <tr>
            <td align="right" class="l-table-edit-td">
                <span class="l-star"></span>&nbsp;收益描述:
            </td>
            <td align="left" class="l-table-edit-td">
                <script name="txtRateSummary" id="txtRateSummary" type="text/plain"></script>
                <script type="text/javascript">
                    window.UEDITOR_CONFIG.initialFrameWidth = 500;
                    window.UEDITOR_CONFIG.initialFrameHeight = 150;
                    rsumeditor = UE.getEditor('txtRateSummary');
                </script>
            </td>
            <td align="left">
            </td>
        </tr>
        <tr>
            <td align="left" class="l-table-edit-td">  
            </td>
            <td align="left">
            </td>
        </tr>
        <tr>
            <td align="left" class="l-table-edit-td"> 
            </td>
            <td align="left">
                <input type="button" value="保存" id="btnSave" name="btnSave" class="l-button" />&nbsp;&nbsp;&nbsp;&nbsp;
                <input type="button" value="取消" id="btnCancel" name="btnCancel" class="l-button" />
            </td>
        </tr>
    </table>
    <br />
</div>
</form>
</div>
<script type="text/javascript">
    $(function () {
        $.validator.addMethod(
                    "notnull",
                    function (value, element, regexp) {
                        if (!value) return true;
                        return !$(element).hasClass("l-text-field-null");
                    },
                    "不能为空"
            );

        $.metadata.setType("attr", "validate");
        var v = $("#frmProduct").validate({
            //debug: true,
            errorPlacement: function (lable, element) {
                if (element.hasClass("l-textarea")) {
                    element.ligerTip({ content: lable.html(), target: element[0] });
                }
                else if (element.hasClass("l-text-field")) {
                    element.parent().ligerTip({ content: lable.html(), target: element[0] });
                }
                else {
                    lable.appendTo(element.parents("td:first").next("td"));
                }
            },
            success: function (lable) {
                lable.ligerHideTip();
                lable.remove();
            },
            submitHandler: function () {
                //todo
            }
        });
        $("#frmProduct").ligerForm();
    });

</script>